// 导入封装的axios模块
import request from "../utils/request.js";


// 登陆
export var login_api = params => {
  return request({
    method: 'post',
    url: 'app/v1_0/authorizations',
    data: params
  });
};
// 发送验证码
export var code_api = mobile => {
  return request({
    method: 'get',
    url: `app/v1_0/sms/codes/${mobile}`
  });
};
// 获取用户信息
export var userinfo_api = () => {
  return request({
    method: 'get',
    url: 'app/v1_0/user',
  });
};
// 获取频道列表
export var channels_api = () => {
  return request({
    method: 'get',
    url: 'app/v1_0/user/channels',
  });
};
// 获取新闻推荐频道
export var newchannels_api = (params) => {
  return request({
    method: 'get',
    url: 'app/v1_1/articles',
    params: {
      channel_id: params.channel_id,
      timestamp: params.timestamp,
      with_top: params.with_top
    }
  });
};
// 获取所有频道列表
export var allchannels_api = () => {
  return request({
    method: 'get',
    url: 'app/v1_0/channels',
  });
};
// 批量删除用户频道
export var delchannels_api = (target) => {
  return request({
    method: 'DELETE',
    url: `app/v1_0/user/channels/${target}`,
  });
};
// 批量增加用户频道
export var addchannels_api = (channels) => {
  return request({
    method: 'PATCH',
    url: 'app/v1_0/user/channels',
    data: {
      channels
    }
  });
};
// 获取联想建议
export var searchSuggestion_api = (q) => {
  return request({
    method: 'get',
    url: 'app/v1_0/suggestion',
    params: {
      q
    }
  });
};
// 获取搜索结果
export var searchResult_api = (params) => {
  return request({
    method: 'get',
    url: 'app/v1_0/search',
    params
  });
};
// 删除用户搜索历史
export var delsearchHistory_api = () => {
  return request({
    method: 'DELETE',
    url: 'app/v1_0/search/histories',
  });
};
// 获取新闻详情
export var getArticle_api = (article_id) => {
  return request({
    method: 'get',
    url: `app/v1_0/articles/${article_id}`,
  });
};
// 关注用户
export var isFollowed_api = (target) => {
  return request({
    method: 'post',
    url: 'app/v1_0/user/followings',
    data: {
      target
    }
  });
};
// 取消关注用户
export var noFollowed_api = (target) => {
  return request({
    method: 'delete',
    url: `app/v1_0/user/followings/${target}`,
  });
};
// 收藏文章
export var collectedart_api = (target) => {
  return request({
    method: 'post',
    url: 'app/v1_0/article/collections',
    data: {
      target
    }
  });
};
// 取消收藏文章
export var nocollectedart_api = (target) => {
  return request({
    method: 'delete',
    url: `app/v1_0/article/collections/${target}`,

  });
};
// 对文章点赞
export var liking_api = (target) => {
  return request({
    method: 'post',
    url: 'app/v1_0/article/likings',
    data: {
      target
    }
  });
};
// 取消对文章点赞
export var noliking_api = (target) => {
  return request({
    method: 'delete',
    url: `app/v1_0/article/likings/${target}`,

  });
};
// 添加评论或评论回复
export var addRecomments_api = (data) => {
  return request({
    method: 'post',
    url: 'app/v1_0/comments',
    data
  });
};
// 获取评论或评论回复
export var getRecomments_api = (params) => {
  return request({
    method: 'get',
    url: 'app/v1_0/comments',
    params
  });
};
// 对评论或评论回复点赞
export var commentliking_api = (target) => {
  return request({
    method: 'post',
    url: 'app/v1_0/comment/likings',
    data: {
      target
    }
  });
};
// 取消评论或评论回复点赞
export var nocommentliking_api = (target) => {
  return request({
    method: 'delete',
    url: `app/v1_0/comment/likings/${target}`,

  });
};
// 编辑用户个人资料
export var editUserinfo_api = (data) => {
  return request({
    method: 'patch',
    url: 'app/v1_0/user/profile',
    data
  })
}
// 获取用户个人资料
export var getUserinfo_api = (target) => {
  return request({
    method: 'get',
    url: 'app/v1_0/user/profile',
    params: {
      target
    }
  })
}
